def momentum_gradient_descent():
    """动量梯度下降示例"""
    
    def loss_function(x):
        return (x - 3)**2 + 0.5 * np.sin(10*x)  # 添加波动模拟复杂地形
    
    def gradient(x):
        return 2*(x-3) + 5*np.cos(10*x)  # 复杂梯度
    
    # 参数初始化
    x = 0.0
    learning_rate = 0.05
    gamma = 0.9  # 动量系数
    velocity = 0  # 速度项
    iterations = 50
    path = []
    
    print("动量梯度下降 vs 普通梯度下降")
    print("迭代次数 | 动量法位置 | 普通法位置")
    print("-" * 40)
    
    # 对比普通梯度下降
    x_normal = 0.0
    
    for i in range(iterations):
        # 动量法
        grad = gradient(x)
        velocity = gamma * velocity + learning_rate * grad
        x = x - velocity
        
        # 普通梯度下降
        grad_normal = gradient(x_normal)
        x_normal = x_normal - learning_rate * grad_normal
        
        path.append((x, x_normal))
        
        if i % 10 == 0:
            print(f"{i:^8} | {x:^10.3f} | {x_normal:^10.3f}")
    
    return path